<?php

/**
 * 玩家游戏日志
 */
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\facade\Db;
    
class LiveusergamelogController extends AdminbaseController {
    
    protected function getGameTypes($k=''){
        $type=array(
            '100' =>'三人转',
        );
        if($k===''){
            return $type;
        }
        
        return $type[$k] ?? '';
    }
    
    function index(){
		$data = $this->request->param();
        $map=[];
		
        $start_time=$data['start_time'] ?? '';
        $end_time=$data['end_time'] ?? '';
        
        if($start_time != ""){
            $map[]=['created_at','>=',date('Y-m-d H:i:s', strtotime($start_time))];
        }

        if($end_time != ""){
            $map[]=['created_at','<=',date('Y-m-d H:i:s', strtotime($end_time) + 60*60*24)];
        }
        $user_id=$data['user_id'] ?? '';
        if($user_id != ''){
            $map[]=['user_id','=',$user_id]; 
        }
        $live_id=$data['live_id'] ?? '';
        if($live_id != ''){
            $map[]=['live_id','=',$live_id]; 
        }

        $lists = Db::connect('mysql_mylive')
            ->name("live_user_game_log")
			->where($map)
			->order("id DESC")
			->paginate(20);
        $lists->each(function($v,$k){
			$v['userinfo']=getUserInfo($v['live_id']);   
            return $v;           
        });
        $lists->appends($data);
        $page = $lists->render();

        $this->assign('lists', $lists);
        $this->assign("page", $page);
        $this->assign("game_type", $this->getGameTypes());
        return $this->fetch();
    }
}